/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CalculationManager;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;

/**
 *
 * @author jfernan
 */
public class CalculationManagerTest_easymock {
 private IMultiplicationService multiplicatorServiceMock;
    private CalculationManager calculationManager;

    @Before
    public void setUp() throws Exception {
        multiplicatorServiceMock = createMock(IMultiplicationService.class);
        calculationManager = new CalculationManager();
        calculationManager.setMultiplicatorService(multiplicatorServiceMock);
    }

    @Test
    public void testCalculationManager() {
        Integer oneProductPrice = 12;
        Integer amount = 3;
        Integer reduction = 6;

        //inject behaviour of MultiplicatorService
        expect(multiplicatorServiceMock
                .multiply(oneProductPrice, amount))
                .andReturn(oneProductPrice * amount);

        //setting up the mock
        replay(multiplicatorServiceMock);

        //object to be tested
        Integer result =
                calculationManager.calculatePrice(oneProductPrice, amount, reduction);

        assertEquals(result, Integer.valueOf( oneProductPrice * amount - reduction) );

        verify(multiplicatorServiceMock);

    }

}